#!/usr/bin/env python
# -*- coding: UTF-8 -*-
#
# Copyright [Gtlions Lai].
# Create Date:
# Update Date:
"""summarization ahout this script.

detail ahout this script

   Class(): summarization about Class
   ...
   function(): summarization about function
   ...
"""
__authors__ = '"Gtlions Lai" <gtlions.l@qq.com>'

import sys
from PyQt4 import QtGui, QtCore


QtCore.QTextCodec.setCodecForTr(QtCore.QTextCodec.codecForName("utf8"))

class StandardDialog(QtGui.QDialog):
    def __init__(self, parent=None):
        #QtGui.QDialog.__init__(self)
        super(StandardDialog, self).__init__(parent)
        self.setWindowTitle("Standard Dialog")
        filetips = "文件对话框"
        filepushbutton = QtGui.QPushButton(self.tr(filetips))
        colorpushbutton = QtGui.QPushButton(self.tr("颜色对话框"))
        fontpushbutton = QtGui.QPushButton(self.tr("字体对话框"))

        self.filelineedit = QtGui.QLineEdit()
        self.colorFrame = QtGui.QFrame()
        self.colorFrame.setFrameShape(QtGui.QFrame.Box)
        self.colorFrame.setAutoFillBackground(True)
        self.fontLineEdit = QtGui.QLineEdit("Hello World!")

        layout = QtGui.QGridLayout()
        layout.addWidget(filepushbutton, 0, 0)
        layout.addWidget(self.filelineedit, 0, 1)
        layout.addWidget(colorpushbutton, 1, 0)
        layout.addWidget(self.colorFrame, 1, 1)
        layout.addWidget(fontpushbutton, 2, 0)
        layout.addWidget(self.filelineedit, 2, 1)

        self.setLayout(layout)

        self.connect(filepushbutton, QtCore.SIGNAL("clicked()"), self.openFile)
        self.connect(colorpushbutton, QtCore.SIGNAL("clicked()"), self.openColor)
        self.connect(fontpushbutton, QtCore.SIGNAL("clicked()"), self.openFont)

    def openFile(self):

        s = QtGui.QFileDialog.getOpenFileName(self, "Open file dialog", "/", "Python files(*.py)")
        self.filelineedit.setText(str(s))

    def openColor(self):

        c = QtGui.QColorDialog.getColor(QtCore.Qt.blue)
        if c.isValid():
            self.colorFrame.setPalette(QtGui.QPalette(c))

    def openFont(self):

        f, ok = QtGui.QFontDialog.getFont()
        if ok:
            self.fontLineEdit.setFont(f)


if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)
    main = StandardDialog()
    main.show()
    sys.exit(app.exec_())